package com.awangyh.jdk8.lambda.proxy;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;

/**
 * Created by admin on 2017/3/31.
 */
public class ProxyDemo {

    public static void main(String[] args) {

        Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("117.90.0.30", 9000));
        try {
            URL url = new URL("https://www.google.com");
            HttpURLConnection connection = (HttpURLConnection)url.openConnection(proxy);
            connection.setConnectTimeout(20000);
            connection.setReadTimeout(30000);
            connection.connect();

            StringBuffer tmp = new StringBuffer();
            try(BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()))){
                String line = null;
                while ((line = in.readLine()) != null ) {
                    tmp.append(line + "\n");
                }
            }
            connection.disconnect();

            System.out.println(tmp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
